﻿Shader "Example01/12通道流光"
{
    Properties
    {
        _MainCol("MainCol",Color)= (1,1,1,1)
        _MainTex ("Texture", 2D) = "white" {}
        _Fluxay ("Fluxay", 2D) = "black" {}
        _Speed("Speed",float) = 1
    }
    SubShader
    {
        Tags
        { 
            "Queue" = "Transparent"
            "RenderType" = "Transparent"
            "PreviewType" ="Plane"
        }
        
        Cull Off
        Lighting Off
        ZWrite Off
        Blend SrcAlpha OneMinusSrcAlpha
        
        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float4 vertex : SV_POSITION;
                float2 uv : TEXCOORD0;
                float2 uv2 : TEXCOORD1;
            };

            float4 _MainCol;
            sampler2D _MainTex;
            float4 _MainTex_ST;
            float _Speed;
            sampler2D _Fluxay;
            float4 _Fluxay_ST;

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv =TRANSFORM_TEX(v.uv,_MainTex);
                o.uv2 =TRANSFORM_TEX(v.uv,_Fluxay);
                o.uv2.x -= _Time.x * _Speed;
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                fixed4 col = tex2D(_MainTex, i.uv);
                fixed mask = tex2D(_Fluxay, i.uv).r;    // 第一套uv是不流动的 用来采样遮罩
                fixed fluxay = tex2D(_Fluxay, i.uv2).g; // 第二套uv是流动的 用来做采样流光
                col.rgb += fluxay * _MainCol.rgb * mask * _MainCol.a;  // 混合颜色
                return col;
            }
            ENDCG
        }
    }
}